#include ".\skinpraser.h"

SkinPraser::SkinPraser(void)
{
}

SkinPraser::~SkinPraser(void)
{
}

extern map<string, RsSkinCursor> g_rsSkinCursorMap;	//the map of the cursor
extern map<string, RsSkinImage>  g_rsSkinImageMap;		//the map of the image

/*
the xml file content like the follow:
<skineasy>
	<resources>
		<cursors>
			<cursor id="my_cursor" src="1.cursor" />
		</crusors>
		<images>
			<image id="my_image" />
		<images>
	</resources>
	<windows>
		<window id="my_dialog" type="dialog" />

		<window id="my_button" type="button" />
	<windows>
</skineasy>
*/
BOOL SkinPraser::PraseXml(LPCTSTR lpszFile)
{
	TiXmlDocument xmlDoc;
	bool bLoad = xmlDoc.LoadFile(lpszFile);
	if (!bLoad)	//load xml file fail.
	{
		ASSERT(FALSE);
		return FALSE;
	}

	//Get the root node. <skineasy> node.
	TiXmlNode * pSkinEasyNode = xmlDoc.FirstChild("skineasy");
	if (!pSkinEasyNode)	//can't find the standard root node.exit the function.
	{
		ASSERT(FALSE);
		return FALSE;
	}

	//resources node ,contain the resources.
	TiXmlNode * pResNode = pSkinEasyNode->FirstChild("resources");
	if (!pResNode)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	//find cursor nodes.
	PraseResCursor(pResNode);

	//Find image nodes
	PraseResImage(pResNode);
	

	//windows nodes.
	TiXmlNode * pWindowsNode = pSkinEasyNode->FirstChild("resources");
	if (!pWindowsNode)
	{
		ASSERT(FALSE);
		return FALSE;
	}

	//Find window node.
	PraseWindows(pWindowsNode);
	return TRUE;
}


BOOL SkinPraser::PraseResCursor(TiXmlNode *pResNode)
{
	TiXmlNode *pCursorNode = pResNode->FirstChild("cursor");
	while (pCursorNode)
	{
		TiXmlElement *pEle = pCursorNode->ToElement();
		string strId = pEle->Attribute("id");
		string strSrc = pEle->Attribute("src");

		RsSkinCursor rsSkinCursor = {0};
		strncpy(rsSkinCursor.szId,strId.c_str(),strId.length());
		strncpy(rsSkinCursor.szFile,strSrc.c_str(),strSrc.length());
		//g_rsSkinCursorMap.insert(make_pair(strId,rsSkinCursor));
		//g_rsSkinCursorMap.insert(make_pair<string, RsSkinCursor>(strId,rsSkinCursor));
		pCursorNode = pResNode->NextSibling("cursor");
	}

	return TRUE;
}

BOOL SkinPraser::PraseResImage(TiXmlNode *pResNode)
{
	TiXmlNode *pImageNode = pResNode->FirstChild("image");
	while (pImageNode)
	{
		TiXmlElement *pEle = pImageNode->ToElement();
		string strId = pEle->Attribute("id");
		string strSrc = pEle->Attribute("src");

		RsSkinImage rsSkinImage = {0};
		strncpy(rsSkinImage.szId,strId.c_str(),strId.length());
		strncpy(rsSkinImage.szFile,strSrc.c_str(),strSrc.length());
		//g_rsSkinImageMap.insert(make_pair<string, RsSkinImage>(strId,rsSkinImage));
		pImageNode = pResNode->NextSibling("image");
	}
	return TRUE;
}

BOOL SkinPraser::PraseWindows(TiXmlNode *pWindowsNode)
{
	TiXmlNode *pWindowNode = pWindowsNode->FirstChild("window");
	while (pWindowNode)
	{
		TiXmlElement *pEle = pWindowNode->ToElement();
		string strId = pEle->Attribute("id");
		string strSrc = pEle->Attribute("src");
		string strType = pEle->Attribute("type");

		//Dialog.
		if (strType.compare("dialog") == 0)
		{
			PraseDialog(pEle);
		}
		else if (strType.compare("static") == 0)
		{
			PraseStatic(pEle);
		}
		else if (strType.compare("button") == 0)
		{
			PraseButton(pEle);
		}
		else if (strType.compare("checkbox") == 0)
		{
			PraseCheckBox(pEle);
		}
		else if (strType.compare("edit") == 0)
		{
			PraseEdit(pEle);
		}
		else if (strType.compare("combobox") == 0)
		{
			PraseComboBox(pEle);
		}
		else if (strType.compare("groupbox") == 0)
		{
			PraseGroupBox(pEle);
		}
		else if (strType.compare("radiobutton") == 0)
		{
			PraseRadioButton(pEle);
		}
		else if (strType.compare("scrollbar") == 0)
		{
		}
		else if (strType.compare("slider") == 0)
		{
			PraseSlider(pEle);
		}
		else if (strType.compare("progress") == 0)
		{
			PraseProgress(pEle);
		}
		else if (strType.compare("spin") == 0)
		{
			PraseSpin(pEle);
		}
		else if (strType.compare("listbox") == 0)
		{
			PraseListBox(pEle);
		}
		else if (strType.compare("listctrl") == 0)
		{
			PraseListCtrl(pEle);
		}
		else
		{
			ASSERT(FALSE);
		}

		pWindowNode = pWindowsNode->NextSibling("window");

	}

	return TRUE;
}

BOOL SkinPraser::PraseDialog(TiXmlElement *pDlgEle)
{
	
	return TRUE;
}

BOOL SkinPraser::PraseStatic(TiXmlElement *pStcEle){return TRUE;}

BOOL SkinPraser::PraseButton(TiXmlElement *pBtnEle){return TRUE;}
BOOL SkinPraser::PraseCheckBox(TiXmlElement *pCkbEle){return TRUE;}
BOOL SkinPraser::PraseEdit(TiXmlElement *pEdtEle){return TRUE;}
BOOL SkinPraser::PraseComboBox(TiXmlElement *pCbxEle){return TRUE;}
BOOL SkinPraser::PraseGroupBox(TiXmlElement *pGpxEle){return TRUE;}
BOOL SkinPraser::PraseRadioButton(TiXmlElement *pRdbEle){return TRUE;}
BOOL SkinPraser::PraseScrollBar(TiXmlElement *pScbEle){return TRUE;}
BOOL SkinPraser::PraseSlider(TiXmlElement *pSldEle){return TRUE;}
BOOL SkinPraser::PraseProgress(TiXmlElement *pPgsEle){return TRUE;}
BOOL SkinPraser::PraseSpin(TiXmlElement *pSpinEle){return TRUE;}
BOOL SkinPraser::PraseListBox(TiXmlElement *pLbxEle){return TRUE;}
BOOL SkinPraser::PraseListCtrl(TiXmlElement *pLclEle){return TRUE;}




















